<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { equipApi } from '@/api/controller'
  import { ToastSuccess, ToastWarning, Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import { ElMessageBox } from 'element-plus';
  import Pagination from "@/components/Pagination/index.vue";
  const action = reactive({
    gameList:[] as Array<any>,
    list:[] as Array<any>,
    total:0,
    dateArr:getDateArray('ymdhis') as Array<number>
  })
  const sale_statusList = [
    {type:0,text:'全部'},
    {type:1,text:'出售中'},
    {type:2,text:'已出售'},
    {type:3,text:'下架'},
  ]
  const equipTypeList = [
    {type:0,text:'全部'},
    {type:1,text:'头部'},
    {type:2,text:'上衣'},
    {type:3,text:'披风'},
    {type:4,text:'武器'},
    {type:5,text:'下装'},
    {type:6,text:'鞋子'},
    {type:7,text:'装饰'},
    {type:8,text:'套装'},
    {type:9,text:'脸型'},
  ]
  const listQuery = reactive({
    game_id:'',
    saleUid:'',
    un_uuid:'',
    page:1,
    limit:20,
    sale_status:0,
    equipType:0,
  })
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      game_id:'',
      saleUid:'',
      un_uuid:'',
      page:1,
      limit:20,
      sale_status:0,
      equipType:0,
    })
    action.dateArr = getDateArray('ymdhis') as Array<number>
    getList()
  }
  const handleDelete = (row:any = {})=>{
    const { auction_id=0 } = row
    if(!auction_id) return ToastWarning('缺少auction_id')
    ElMessageBox.confirm("确定下架此商品吗?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(async () => {
      const loading = Toastloading();
      equipApi.equipauction_unsale({auction_id}).then(()=>{
        ToastSuccess("下架成功!");
        loading.close();
        getList();
      }).catch(()=>{
        loading.close();
      })
    }).catch(() => {});
  }
  const getGameIdList = async()=>{
    const res = await equipApi.gameSwitch()
    const { data=[] } = res || {}
    action.gameList = data
  }
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const getList = async()=>{
    const loading = Toastloading()
    const { playTime:start_time = '', endTime:end_time='' } = getPlayEndTime(action.dateArr)
    const res = await equipApi.equipauctionlist({
      ...listQuery,
      start_time,
      end_time
    })
    loading.close()
    const { data=[], total=0 } = res.data || {}
    action.total = total
    action.list = data
  }
  onMounted(() => {
    getGameIdList()
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">出售状态：</div>
          <el-select v-model="listQuery.sale_status" clearable placeholder="请选择出售状态">
            <el-option v-for="item in sale_statusList" :label="item.text" :value="item.type" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">出售用户UUID：</div>
          <el-input v-model="listQuery.saleUid" placeholder="请输入用户UUID"/>
        </div>
        <div class="labelItem">
          <div class="label">公会长UUID：</div>
          <el-input v-model="listQuery.un_uuid" placeholder="请输入用户UUID"/>
        </div>
        <div class="labelItem">
          <div class="label">装备类型：</div>
          <el-select v-model="listQuery.equipType" clearable placeholder="请选择装备类型">
            <el-option v-for="item in equipTypeList" :label="item.text" :value="item.type" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">时间：</div>
          <el-date-picker
            v-model="action.dateArr"
            type="datetimerange"
            format="YYYY-MM-DD HH:mm:ss "
            value-format="YYYY-MM-DD HH:mm:ss"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </div>
        
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="120" prop="auction_id" label="订单id" />
      <el-table-column width="120" prop="equip_type_name" label="类型名称" />
      <el-table-column min-width="120" prop="equip_id" label="装备id" />
      <el-table-column min-width="120" prop="equip_name" label="装备名称" />
      <el-table-column min-width="140" prop="equip_price" label="出售价格" />
      <el-table-column min-width="140" prop="sale_user_name" label="出售用户名称" />
      <el-table-column min-width="140" prop="sale_user_uuid" label="出售用户UUID" />
      <el-table-column min-width="140" prop="buy_user_uuid" label="购买用户UUID" />
      <el-table-column min-width="140" prop="buy_user_name" label="购买用户名称" />
      <el-table-column min-width="140" prop="union_user_name" label="公会名称" />
      <el-table-column min-width="140" prop="union_user_uuid" label="公会长UUID" />
      <el-table-column min-width="140" prop="union_name" label="公会名称" />
      <el-table-column min-width="140" prop="sale_status" label="出售状态">
        <template #default="scope">
          {{ sale_statusList.find(res=>res.type == scope.row.sale_status)?.text || scope.row.sale_status }}
        </template>
      </el-table-column>
      <el-table-column width="120" fixed=right label="操作">
        <template #default="scope">
          <el-button v-if="scope.row.sale_status == 1" type="danger" @click="handleDelete(scope.row)">下架</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>

<style lang='scss' scoped>
  
</style>